﻿namespace FTchina.Upgrade
{
    using System;
    using System.Xml;

    public class UpgradeCheck
    {
        private FileList _list;
        private string _newVer;
        private FileList _remove;
        private string _sql;

        public UpgradeCheck(string ver)
        {
            FileItem item;
            this._newVer = string.Empty;
            this._list = new FileList();
            this._remove = new FileList();
            this._sql = string.Empty;
            XmlDocument document = new XmlDocument();
            document.Load(string.Format("http://{0}/Upgrade/{1}/Files.xml", UpgradeCore.ServerName, ver));
            this._newVer = document.SelectSingleNode("/upgrade/version").InnerText;
            if (document.SelectNodes("/upgrade/sql").Count > 0)
            {
                this._sql = document.SelectSingleNode("/upgrade/sql").InnerText;
            }
            if ((document.SelectNodes("/upgrade/list").Count > 0) && (document.SelectNodes("/upgrade/list/item").Count > 0))
            {
                foreach (XmlNode node in document.SelectNodes("/upgrade/list/item"))
                {
                    item = new FileItem();
                    item.FilePath = node.Attributes["path"].Value;
                    if (!string.IsNullOrEmpty(item.FilePath))
                    {
                        this._list.Add(item);
                    }
                }
            }
            if ((document.SelectNodes("/upgrade/remove").Count > 0) && (document.SelectNodes("/upgrade/remove/item").Count > 0))
            {
                foreach (XmlNode node in document.SelectNodes("/upgrade/remove/item"))
                {
                    item = new FileItem();
                    item.FilePath = node.Attributes["path"].Value;
                    if (!string.IsNullOrEmpty(item.FilePath))
                    {
                        this._remove.Add(item);
                    }
                }
            }
        }

        public FileList GetFileList
        {
            get
            {
                return this._list;
            }
        }

        public FileList GetRemoveList
        {
            get
            {
                return this._remove;
            }
        }

        public string SQL
        {
            get
            {
                return this._sql;
            }
        }

        public string Version
        {
            get
            {
                return this._newVer;
            }
        }
    }
}

